package com.taysear.parcel.fieldfactory;

import com.taysear.parcel.util.Constants;
import com.vaadin.addon.jpacontainer.fieldfactory.FieldFactory;
import com.vaadin.data.Item;
import com.vaadin.ui.Component;
import com.vaadin.ui.Field;
import com.vaadin.ui.TextField;

public class CurrencyFieldFactory extends FieldFactory {
	
	public final TextField id = new TextField("Id");
	final TextField name = new TextField("Name");

	@Override
	public Field createField(Item item, Object propertyId, Component uiContext) {
		Field f;
		if ("id".equals(propertyId)) {
			id.setRequired(true);
			id.setWidth(Constants.COMMON_FIELD_WIDTH);
			return id;
		} else if ("name".equals(propertyId)) {
			name.setRequired(true);
			name.setWidth(Constants.COMMON_FIELD_WIDTH);
			name.setRequiredError("Name is required");
			name.setNullRepresentation("");
			return name;
		} else {
			// Use the super class to create a suitable field base on the
			// property type.
			f = super.createField(item, propertyId, uiContext);
		}
		return f;
	}
}
